import React, { Fragment, useState, useEffect } from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Card, message } from 'antd';
import SF from 'react-antd-super-form';
import * as api from './service';
const antd = require('antd');


export default (props)=>{
  // const [pageId] = useState(props.match.params.pageId)
  // console.log(antd)

  const [searchData, setSearchData] = useState([]);
  const [columns, setColumns] = useState([]);
  const [action, setAction] = useState('');
  useEffect(()=>{
    const {pageId} = props.match.params;
    api.queryPageConfig(pageId).then(res=>{
      if(res.status){
        message.success('操作')
        const entry = res.entry || {};
        setSearchData(entry.searchData||[]);
        setColumns(entry.columns||[])
        setAction(entry.action)
      } else {
        message.error(res.message)
      }
    })

    return ()=>false;
  },[props.match.params.pageId])


  return (<PageHeaderWrapper content=" 这个页面只有 admin 权限才能查看">
    <Card>
    动态测试页面 ，参数：{JSON.stringify(props.match.params||{})}
      <SF
        search={{
          layout: 'inline',
          data: searchData.map(item=>{
            return {
              ...item,
              cType: antd[item.cType]||item.cType,
            }
          })
        }}
        table={{
          isInit: action===""?true:false,
          action:async (params)=>{
            console.log(action)
            return api.getData(action,params)
          },
          columns
        }}
      />
    </Card>
    </PageHeaderWrapper>)
}